<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "psacar_member_serviceinfo.php" ?>
<?php include "psacar_userinfo.php" ?>
<?php include "userfn7.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Create page object
$psacar_member_service_add = new cpsacar_member_service_add();
$Page =& $psacar_member_service_add;

// Page init
$psacar_member_service_add->Page_Init();

// Page main
$psacar_member_service_add->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--

// Create page object
var psacar_member_service_add = new ew_Page("psacar_member_service_add");

// page properties
psacar_member_service_add.PageID = "add"; // page ID
psacar_member_service_add.FormID = "fpsacar_member_serviceadd"; // form ID
var EW_PAGE_ID = psacar_member_service_add.PageID; // for backward compatibility

// extend page with ValidateForm function
psacar_member_service_add.ValidateForm = function(fobj) {
	ew_PostAutoSuggest(fobj);
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_status"];
		if (elm && !ew_HasValue(elm))
			return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_member_service->status->FldCaption()) ?>");
		elm = fobj.elements["x" + infix + "_status"];
		if (elm && !ew_CheckInteger(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_member_service->status->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_expiration_date"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_member_service->expiration_date->FldErrMsg()) ?>");

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}
	return true;
}

// extend page with Form_CustomValidate function
psacar_member_service_add.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
psacar_member_service_add.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
psacar_member_service_add.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<script type="text/javascript">
<!--
var ew_DHTMLEditors = [];

//-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-cold-1.css" title="win2k-1">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<p><span class="phpmaker"><?php echo $Language->Phrase("Add") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $psacar_member_service->TableCaption() ?><br><br>
<a href="<?php echo $psacar_member_service->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$psacar_member_service_add->ShowMessage();
?>
<form name="fpsacar_member_serviceadd" id="fpsacar_member_serviceadd" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return psacar_member_service_add.ValidateForm(this);">
<p>
<input type="hidden" name="t" id="t" value="psacar_member_service">
<input type="hidden" name="a_add" id="a_add" value="A">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
    <?php if ($psacar_member_service->member_id->Visible) { // member_id ?>
	<tr<?php echo $psacar_member_service->member_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_member_service->member_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_member_service->member_id->CellAttributes() ?>><span id="el_member_id">
<select id="x_member_id" name="x_member_id" title="<?php echo $psacar_member_service->member_id->FldTitle() ?>"<?php echo $psacar_member_service->member_id->EditAttributes() ?>>
<?php
if (is_array($psacar_member_service->member_id->EditValue)) {
	$arwrk = $psacar_member_service->member_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_member_service->member_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
<?php if ($arwrk[$rowcntwrk][2] <> "") { ?>
<?php echo ew_ValueSeparator($rowcntwrk) ?><?php echo $arwrk[$rowcntwrk][2] ?>
<?php } ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_member_service->member_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_member_service->service_id->Visible) { // service_id ?>
	<tr<?php echo $psacar_member_service->service_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_member_service->service_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_member_service->service_id->CellAttributes() ?>><span id="el_service_id">
<select id="x_service_id" name="x_service_id" title="<?php echo $psacar_member_service->service_id->FldTitle() ?>"<?php echo $psacar_member_service->service_id->EditAttributes() ?>>
<?php
if (is_array($psacar_member_service->service_id->EditValue)) {
	$arwrk = $psacar_member_service->service_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_member_service->service_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_member_service->service_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_member_service->location_id->Visible) { // location_id ?>
	<tr<?php echo $psacar_member_service->location_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_member_service->location_id->FldCaption() ?></td>
		<td<?php echo $psacar_member_service->location_id->CellAttributes() ?>><span id="el_location_id">
<select id="x_location_id" name="x_location_id" title="<?php echo $psacar_member_service->location_id->FldTitle() ?>"<?php echo $psacar_member_service->location_id->EditAttributes() ?>>
<?php
if (is_array($psacar_member_service->location_id->EditValue)) {
	$arwrk = $psacar_member_service->location_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_member_service->location_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
<?php if ($arwrk[$rowcntwrk][2] <> "") { ?>
<?php echo ew_ValueSeparator($rowcntwrk) ?><?php echo $arwrk[$rowcntwrk][2] ?>
<?php } ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_member_service->location_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php 
/*
if ($psacar_member_service->year->Visible) { // year ?>
	<tr<?php echo $psacar_member_service->year->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_member_service->year->FldCaption() ?></td>
		<td<?php echo $psacar_member_service->year->CellAttributes() ?>><span id="el_year">
<select id="x_year" name="x_year" title="<?php echo $psacar_member_service->year->FldTitle() ?>"<?php echo $psacar_member_service->year->EditAttributes() ?>>
<?php
if (is_array($psacar_member_service->year->EditValue)) {
	$arwrk = $psacar_member_service->year->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_member_service->year->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_member_service->year->CustomMsg ?></td>
	</tr>
<?php } 
*/
?>
<?php if ($psacar_member_service->make_id->Visible) { // make_id ?>
	<tr<?php echo $psacar_member_service->make_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_member_service->make_id->FldCaption() ?></td>
		<td<?php echo $psacar_member_service->make_id->CellAttributes() ?>><span id="el_make_id">
<select id="x_make_id" name="x_make_id" title="<?php echo $psacar_member_service->make_id->FldTitle() ?>"<?php echo $psacar_member_service->make_id->EditAttributes() ?>>
<?php
if (is_array($psacar_member_service->make_id->EditValue)) {
	$arwrk = $psacar_member_service->make_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_member_service->make_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_member_service->make_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php 
/*
if ($psacar_member_service->model_id->Visible) { // model_id ?>
	<tr<?php echo $psacar_member_service->model_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_member_service->model_id->FldCaption() ?></td>
		<td<?php echo $psacar_member_service->model_id->CellAttributes() ?>><span id="el_model_id">
<select id="x_model_id" name="x_model_id" title="<?php echo $psacar_member_service->model_id->FldTitle() ?>"<?php echo $psacar_member_service->model_id->EditAttributes() ?>>
<?php
if (is_array($psacar_member_service->model_id->EditValue)) {
	$arwrk = $psacar_member_service->model_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_member_service->model_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_member_service->model_id->CustomMsg ?></td>
	</tr>
<?php }
*/
?>
<?php 
/*
if ($psacar_member_service->ref_code->Visible) { // ref_code ?>
	<tr<?php echo $psacar_member_service->ref_code->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_member_service->ref_code->FldCaption() ?></td>
		<td<?php echo $psacar_member_service->ref_code->CellAttributes() ?>><span id="el_ref_code">
<input type="text" name="x_ref_code" id="x_ref_code" title="<?php echo $psacar_member_service->ref_code->FldTitle() ?>" size="30" maxlength="255" value="<?php echo $psacar_member_service->ref_code->EditValue ?>"<?php echo $psacar_member_service->ref_code->EditAttributes() ?>>
</span><?php echo $psacar_member_service->ref_code->CustomMsg ?></td>
	</tr>
<?php } 
*/
?>
<?php if ($psacar_member_service->status->Visible) { // status ?>
	<tr<?php echo $psacar_member_service->status->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_member_service->status->FldCaption() ?></td>
		<td<?php echo $psacar_member_service->status->CellAttributes() ?>><span id="el_status">
<select id="x_status" name="x_status" title="<?php echo $psacar_member_service->status->FldTitle() ?>"<?php echo $psacar_member_service->status->EditAttributes() ?>>
<?php
if (is_array($psacar_member_service->status->EditValue)) {
	$arwrk = $psacar_member_service->status->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_member_service->status->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_member_service->status->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_member_service->expiration_date->Visible) { // expiration_date ?>
	<tr<?php echo $psacar_member_service->expiration_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_member_service->expiration_date->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
		<td<?php echo $psacar_member_service->expiration_date->CellAttributes() ?>><span id="el_expiration_date">
<input type="text" name="x_expiration_date" id="x_expiration_date" title="<?php echo $psacar_member_service->expiration_date->FldTitle() ?>" value="<?php echo $psacar_member_service->expiration_date->EditValue ?>"<?php echo $psacar_member_service->expiration_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_expiration_date" name="cal_x_expiration_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_expiration_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_expiration_date" // button id
});
</script>
</span><?php echo $psacar_member_service->expiration_date->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("AddBtn")) ?>">
</form>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php
$psacar_member_service_add->Page_Terminate();
?>
<?php

//
// Page class
//
class cpsacar_member_service_add {

	// Page ID
	var $PageID = 'add';

	// Table name
	var $TableName = 'psacar_member_service';

	// Page object name
	var $PageObjName = 'psacar_member_service_add';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $psacar_member_service;
		if ($psacar_member_service->UseTokenInUrl) $PageUrl .= "t=" . $psacar_member_service->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Page URLs
	var $AddUrl;
	var $EditUrl;
	var $CopyUrl;
	var $DeleteUrl;
	var $ViewUrl;
	var $ListUrl;

	// Export URLs
	var $ExportPrintUrl;
	var $ExportHtmlUrl;
	var $ExportExcelUrl;
	var $ExportWordUrl;
	var $ExportXmlUrl;
	var $ExportCsvUrl;

	// Update URLs
	var $InlineAddUrl;
	var $InlineCopyUrl;
	var $InlineEditUrl;
	var $GridAddUrl;
	var $GridEditUrl;
	var $MultiDeleteUrl;
	var $MultiUpdateUrl;

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
			$_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = $v;
		}
	}

	// Show message
	function ShowMessage() {
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage);
		if ($sMessage <> "") { // Message in Session, display
			echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm, $psacar_member_service;
		if ($psacar_member_service->UseTokenInUrl) {
			if ($objForm)
				return ($psacar_member_service->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($psacar_member_service->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function cpsacar_member_service_add() {
		global $conn, $Language;

		// Language object
		$Language = new cLanguage();

		// Table object (psacar_member_service)
		$GLOBALS["psacar_member_service"] = new cpsacar_member_service();

		// Table object (psacar_user)
		$GLOBALS['psacar_user'] = new cpsacar_user();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'add', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'psacar_member_service', TRUE);

		// Start timer
		$GLOBALS["gsTimer"] = new cTimer();

		// Open connection
		$conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
		global $psacar_member_service;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}

		// Create form object
		$objForm = new cFormObj();

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		$this->Page_Redirecting($url);
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $sDbMasterFilter = "";
	var $sDbDetailFilter = "";
	var $lPriv = 0;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError, $psacar_member_service;

		// Load key values from QueryString
		$bCopy = TRUE;
		if (@$_GET["id"] != "") {
		  $psacar_member_service->id->setQueryStringValue($_GET["id"]);
		} else {
		  $bCopy = FALSE;
		}

		// Process form if post back
		if (@$_POST["a_add"] <> "") {
		   $psacar_member_service->CurrentAction = $_POST["a_add"]; // Get form action
		  $this->LoadFormValues(); // Load form values

			// Validate form
			if (!$this->ValidateForm()) {
				$psacar_member_service->CurrentAction = "I"; // Form error, reset action
				$this->setMessage($gsFormError);
			}
		} else { // Not post back
		  if ($bCopy) {
		    $psacar_member_service->CurrentAction = "C"; // Copy record
		  } else {
		    $psacar_member_service->CurrentAction = "I"; // Display blank record
		    $this->LoadDefaultValues(); // Load default values
		  }
		}

		// Perform action based on action code
		switch ($psacar_member_service->CurrentAction) {
		  case "I": // Blank record, no action required
				break;
		  case "C": // Copy an existing record
		   if (!$this->LoadRow()) { // Load record based on key
		      $this->setMessage($Language->Phrase("NoRecord")); // No record found
		      $this->Page_Terminate("psacar_member_servicelist.php"); // No matching record, return to list
		    }
				break;
		  case "A": // ' Add new record
				$psacar_member_service->SendEmail = TRUE; // Send email on add success
		    if ($this->AddRow()) { // Add successful
		      $this->setMessage($Language->Phrase("AddSuccess")); // Set up success message
					$sReturnUrl = $psacar_member_service->getReturnUrl();
					$this->Page_Terminate($sReturnUrl); // Clean up and return
		    } else {
		      $this->RestoreFormValues(); // Add failed, restore form values
		    }
		}

		// Render row based on row type
		$psacar_member_service->RowType = EW_ROWTYPE_ADD;  // Render add type

		// Render row
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm, $psacar_member_service;

		// Get upload data
	}

	// Load default values
	function LoadDefaultValues() {
		global $psacar_member_service;
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $psacar_member_service;
		$psacar_member_service->service_id->setFormValue($objForm->GetValue("x_service_id"));
		$psacar_member_service->location_id->setFormValue($objForm->GetValue("x_location_id"));
		$psacar_member_service->year->setFormValue($objForm->GetValue("x_year"));
		$psacar_member_service->make_id->setFormValue($objForm->GetValue("x_make_id"));
		$psacar_member_service->model_id->setFormValue($objForm->GetValue("x_model_id"));
		$psacar_member_service->ref_code->setFormValue($objForm->GetValue("x_ref_code"));
		$psacar_member_service->status->setFormValue($objForm->GetValue("x_status"));
		$psacar_member_service->member_id->setFormValue($objForm->GetValue("x_member_id"));
		$psacar_member_service->expiration_date->setFormValue($objForm->GetValue("x_expiration_date"));
		$psacar_member_service->expiration_date->CurrentValue = ew_UnFormatDateTime($psacar_member_service->expiration_date->CurrentValue, 5);
		$psacar_member_service->id->setFormValue($objForm->GetValue("x_id"));
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $psacar_member_service;
		$psacar_member_service->id->CurrentValue = $psacar_member_service->id->FormValue;
		$psacar_member_service->service_id->CurrentValue = $psacar_member_service->service_id->FormValue;
		$psacar_member_service->location_id->CurrentValue = $psacar_member_service->location_id->FormValue;
		$psacar_member_service->year->CurrentValue = $psacar_member_service->year->FormValue;
		$psacar_member_service->make_id->CurrentValue = $psacar_member_service->make_id->FormValue;
		$psacar_member_service->model_id->CurrentValue = $psacar_member_service->model_id->FormValue;
		$psacar_member_service->ref_code->CurrentValue = $psacar_member_service->ref_code->FormValue;
		$psacar_member_service->status->CurrentValue = $psacar_member_service->status->FormValue;
		$psacar_member_service->member_id->CurrentValue = $psacar_member_service->member_id->FormValue;
		$psacar_member_service->expiration_date->CurrentValue = $psacar_member_service->expiration_date->FormValue;
		$psacar_member_service->expiration_date->CurrentValue = ew_UnFormatDateTime($psacar_member_service->expiration_date->CurrentValue, 5);
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $psacar_member_service;
		$sFilter = $psacar_member_service->KeyFilter();

		// Call Row Selecting event
		$psacar_member_service->Row_Selecting($sFilter);

		// Load SQL based on filter
		$psacar_member_service->CurrentFilter = $sFilter;
		$sSql = $psacar_member_service->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values

			// Call Row Selected event
			$psacar_member_service->Row_Selected($rs);
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $psacar_member_service;
		$psacar_member_service->id->setDbValue($rs->fields('id'));
		$psacar_member_service->service_id->setDbValue($rs->fields('service_id'));
		$psacar_member_service->location_id->setDbValue($rs->fields('location_id'));
		$psacar_member_service->year->setDbValue($rs->fields('year'));
		$psacar_member_service->make_id->setDbValue($rs->fields('make_id'));
		$psacar_member_service->model_id->setDbValue($rs->fields('model_id'));
		$psacar_member_service->ref_code->setDbValue($rs->fields('ref_code'));
		$psacar_member_service->status->setDbValue($rs->fields('status'));
		$psacar_member_service->member_id->setDbValue($rs->fields('member_id'));
		$psacar_member_service->expiration_date->setDbValue($rs->fields('expiration_date'));
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language, $psacar_member_service;

		// Initialize URLs
		// Call Row_Rendering event

		$psacar_member_service->Row_Rendering();

		// Common render codes for all row types
		// service_id

		$psacar_member_service->service_id->CellCssStyle = ""; $psacar_member_service->service_id->CellCssClass = "";
		$psacar_member_service->service_id->CellAttrs = array(); $psacar_member_service->service_id->ViewAttrs = array(); $psacar_member_service->service_id->EditAttrs = array();

		// location_id
		$psacar_member_service->location_id->CellCssStyle = ""; $psacar_member_service->location_id->CellCssClass = "";
		$psacar_member_service->location_id->CellAttrs = array(); $psacar_member_service->location_id->ViewAttrs = array(); $psacar_member_service->location_id->EditAttrs = array();

		// year
		$psacar_member_service->year->CellCssStyle = ""; $psacar_member_service->year->CellCssClass = "";
		$psacar_member_service->year->CellAttrs = array(); $psacar_member_service->year->ViewAttrs = array(); $psacar_member_service->year->EditAttrs = array();

		// make_id
		$psacar_member_service->make_id->CellCssStyle = ""; $psacar_member_service->make_id->CellCssClass = "";
		$psacar_member_service->make_id->CellAttrs = array(); $psacar_member_service->make_id->ViewAttrs = array(); $psacar_member_service->make_id->EditAttrs = array();

		// model_id
		$psacar_member_service->model_id->CellCssStyle = ""; $psacar_member_service->model_id->CellCssClass = "";
		$psacar_member_service->model_id->CellAttrs = array(); $psacar_member_service->model_id->ViewAttrs = array(); $psacar_member_service->model_id->EditAttrs = array();

		// ref_code
		$psacar_member_service->ref_code->CellCssStyle = ""; $psacar_member_service->ref_code->CellCssClass = "";
		$psacar_member_service->ref_code->CellAttrs = array(); $psacar_member_service->ref_code->ViewAttrs = array(); $psacar_member_service->ref_code->EditAttrs = array();

		// status
		$psacar_member_service->status->CellCssStyle = ""; $psacar_member_service->status->CellCssClass = "";
		$psacar_member_service->status->CellAttrs = array(); $psacar_member_service->status->ViewAttrs = array(); $psacar_member_service->status->EditAttrs = array();

		// member_id
		$psacar_member_service->member_id->CellCssStyle = ""; $psacar_member_service->member_id->CellCssClass = "";
		$psacar_member_service->member_id->CellAttrs = array(); $psacar_member_service->member_id->ViewAttrs = array(); $psacar_member_service->member_id->EditAttrs = array();

		// expiration_date
		$psacar_member_service->expiration_date->CellCssStyle = ""; $psacar_member_service->expiration_date->CellCssClass = "";
		$psacar_member_service->expiration_date->CellAttrs = array(); $psacar_member_service->expiration_date->ViewAttrs = array(); $psacar_member_service->expiration_date->EditAttrs = array();
		if ($psacar_member_service->RowType == EW_ROWTYPE_VIEW) { // View row

		} elseif ($psacar_member_service->RowType == EW_ROWTYPE_ADD) { // Add row

			// service_id
			$psacar_member_service->service_id->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_service`";
			$sWhereWrk = "";
			if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
			$sWhereWrk .= "(" . "`parent_id` = 0" . ")";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_member_service->service_id->EditValue = $arwrk;

			// location_id
			$psacar_member_service->location_id->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `province`, `district`, '' AS SelectFilterFld FROM `psacar_location`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), ""));
			$psacar_member_service->location_id->EditValue = $arwrk;

			// year
			$psacar_member_service->year->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `code`, `year`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_year`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_member_service->year->EditValue = $arwrk;

			// make_id
			$psacar_member_service->make_id->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_make`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_member_service->make_id->EditValue = $arwrk;

			// model_id
			$psacar_member_service->model_id->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_model`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_member_service->model_id->EditValue = $arwrk;

			// ref_code
			$psacar_member_service->ref_code->EditCustomAttributes = "";
			$psacar_member_service->ref_code->EditValue = ew_HtmlEncode($psacar_member_service->ref_code->CurrentValue);

			// status
			$psacar_member_service->status->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("0", "Pendding");
			$arwrk[] = array("1", "Approved");
			$arwrk[] = array("2", "Deleted");
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_member_service->status->EditValue = $arwrk;

			// member_id
			$psacar_member_service->member_id->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `last_name`, `company`, '' AS SelectFilterFld FROM `psacar_member`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), ""));
			$psacar_member_service->member_id->EditValue = $arwrk;

			// expiration_date
			$psacar_member_service->expiration_date->EditCustomAttributes = "";
			$psacar_member_service->expiration_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_member_service->expiration_date->CurrentValue, 5));
		}

		// Call Row Rendered event
		if ($psacar_member_service->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$psacar_member_service->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError, $psacar_member_service;

		// Initialize form error message
		$gsFormError = "";

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!is_null($psacar_member_service->status->FormValue) && $psacar_member_service->status->FormValue == "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_member_service->status->FldCaption();
		}
		if (!ew_CheckInteger($psacar_member_service->status->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $psacar_member_service->status->FldErrMsg();
		}
		if (!ew_CheckDate($psacar_member_service->expiration_date->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $psacar_member_service->expiration_date->FldErrMsg();
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $sFormCustomError;
		}
		return $ValidateForm;
	}

	// Add record
	function AddRow() {
		global $conn, $Language, $Security, $psacar_member_service;
		$rsnew = array();

		// service_id
		$psacar_member_service->service_id->SetDbValueDef($rsnew, $psacar_member_service->service_id->CurrentValue, 0, FALSE);

		// location_id
		$psacar_member_service->location_id->SetDbValueDef($rsnew, $psacar_member_service->location_id->CurrentValue, NULL, FALSE);

		// year
		$psacar_member_service->year->SetDbValueDef($rsnew, $psacar_member_service->year->CurrentValue, NULL, FALSE);

		// make_id
		$psacar_member_service->make_id->SetDbValueDef($rsnew, $psacar_member_service->make_id->CurrentValue, NULL, FALSE);

		// model_id
		$psacar_member_service->model_id->SetDbValueDef($rsnew, $psacar_member_service->model_id->CurrentValue, NULL, FALSE);

		// ref_code
		$psacar_member_service->ref_code->SetDbValueDef($rsnew, $psacar_member_service->ref_code->CurrentValue, NULL, FALSE);

		// status
		$psacar_member_service->status->SetDbValueDef($rsnew, $psacar_member_service->status->CurrentValue, 0, FALSE);

		// member_id
		$psacar_member_service->member_id->SetDbValueDef($rsnew, $psacar_member_service->member_id->CurrentValue, 0, FALSE);

		// expiration_date
		$psacar_member_service->expiration_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_member_service->expiration_date->CurrentValue, 5, FALSE), ew_CurrentDate());

		// Call Row Inserting event
		$bInsertRow = $psacar_member_service->Row_Inserting($rsnew);
		if ($bInsertRow) {
			$conn->raiseErrorFn = 'ew_ErrorFn';
			$AddRow = $conn->Execute($psacar_member_service->InsertSQL($rsnew));
			$conn->raiseErrorFn = '';
		} else {
			if ($psacar_member_service->CancelMessage <> "") {
				$this->setMessage($psacar_member_service->CancelMessage);
				$psacar_member_service->CancelMessage = "";
			} else {
				$this->setMessage($Language->Phrase("InsertCancelled"));
			}
			$AddRow = FALSE;
		}
		if ($AddRow) {
			$psacar_member_service->id->setDbValue($conn->Insert_ID());
			$rsnew['id'] = $psacar_member_service->id->DbValue;

			// Call Row Inserted event
			$psacar_member_service->Row_Inserted($rsnew);
		}
		return $AddRow;
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	function Message_Showing(&$msg) {

		// Example:
		//$msg = "your new message";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
